package org.aplombh.java.leetcode.all;

public class _11盛最多水的容器 {

}

// 暴力
class Solution11_1 {
    public int maxArea(int[] height) {
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i + 1; j < height.length; j++) {
                int h = Math.min(height[i], height[j]);
                int l = j - i;

                max = Math.max(max, h * l);
            }
        }
        return max;
    }
}

// 双指针
class Solution11_2 {
    public int maxArea(int[] height) {
        int max = 0;
        for (int i = 0, j = height.length - 1; i < j; ) {


            int h = Math.min(height[i], height[j]);
            int l = j - i;

            if (height[i] > height[j]) {
                j--;
            } else {
                i++;
            }
            max = Math.max(max, h * l);

        }
        return max;
    }
}